package com.imooc.controller;

import com.imooc.controller.frontend.MainPageController;
import com.imooc.controller.superadmin.HeadLineOperationController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/")
public class DispathcherServlet extends HttpServlet {

    public static final String GET = "GET";
    public static final String FRONTEND_GETMAINPAGEINFO = "/frontend/getmainpageinfo";
    public static final String POST = "POST";
    Logger LOGGER = LoggerFactory.getLogger(DispathcherServlet.class);

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        LOGGER.info("request path is : " + req.getServletPath());
        LOGGER.info("request method is : " + req.getMethod());

        if (FRONTEND_GETMAINPAGEINFO.equals(req.getServletPath()) && GET.equals(req.getMethod())) {
            new MainPageController().getMainPageInfo(req, resp);
        } else if (("" +
                "").equals(req.getServletPath()) && POST.equals(req.getMethod())) {
            new HeadLineOperationController().addHeadLine(req, resp);
        }
    }
}
